<%@ page language="java" import="java.util.*,school.dao.*,school.entity.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'addsubject.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script>
	 function checkForm(f){
		 //var name=document.getElementsByName("subjectname")[0];
		 var name=f.subjectname.value;
		 if(name.length<1||name.length>100){
			 alert("课程名不能为空或者太长！");
			 return false;
		 }
		 var hour=f.classhour.value;
		 if(hour=="" ||isNaN(hour)){
			 alert("课时必须是数字！");
			 return false;
		 }
		 return true;
	 }
	 function checkClass(t){
		
		 if(isNaN(t.value)){
			 document.getElementById("hour").style.color="red";
			 document.getElementById("hour").innerHTML="您输入的不是数字";
		 }else{
			 document.getElementById("hour").style.color="green";
			 document.getElementById("hour").innerHTML="ok";
		 }
	 }
	</script>
  </head>
  <body>
  	<%@include file="checkLogin.jsp" %>
  	<%-- <jsp:include page="checkLogin.jsp"></jsp:include> --%>
     <form action="doSaveSubject.jsp" method="post" onsubmit="return checkForm(this)">
			<p>
				<label>课程名称</label>
				<input type="text" name="subjectname" />
			</p>
			<p>
				<label>课时</label>
				<input type="number" name="classhour" onkeyup="checkClass(this)" /><span id="hour" style="color:red"></span>
			</p>
			<p>
				<label>年级</label>
				<select name="gradeid">
					<% 
				 	//double student=0;
					List<Grade> list=GradeDao.DAO.findALL();
					for(Grade g:list){
					%>
					<option value="<%=g.getId()%>"><%=g.getGname()%></option>
					<%} %>
				</select>
			</p>
			<input type="submit" value="添加"/>
	</form>
  </body>
</html>
